import request from '@/utils/request'

// 查询商品SKU列表
export function listGoodsSku (goodsId, query) {
  return request({
    url: '/goods/goods',
    method: 'get',
    params: query
  })
}

// 商品SKU上架状态修改
export function changeGoodsSkuMarketEnable (goodsId, goodsSkuId, marketEnable) {
  const data = { marketEnable }
  return request({
    url: '/goods/goods/' + goodsId + '/sku/' + goodsSkuId + '/marketEnable',
    method: 'put',
    data: data
  })
}

// 商品底部导航状态修改
export function updateCeiling (skuId, property, data) {
  return request({
    url: '/goods/goods/sku/ceiling/' + skuId + '/' + property,
    method: 'put',
    data: data
  })
}

// 商品OTC专销状态修改
export function changeGoodsSkuProprietary (goodsId, goodsSkuId, proprietary) {
  const data = { proprietary }
  return request({
    url: '/goods/goods/' + goodsId + '/sku/' + goodsSkuId + '/proprietary',
    method: 'put',
    data: data
  })
}

// 商品控销状态修改
export function changeGoodsSkuControl (goodsId, goodsSkuId, control) {
  const data = { control }
  return request({
    url: '/goods/goods/' + goodsId + '/sku/' + goodsSkuId + '/control',
    method: 'put',
    data: data
  })
}

// 商品开票员专销状态修改
export function changeGoodsSkuPreferred (goodsId, goodsSkuId, preferred) {
  const data = { preferred }
  return request({
    url: '/goods/goods/' + goodsId + '/sku/' + goodsSkuId + '/preferred',
    method: 'put',
    data: data
  })
}

// 商品中药状态修改
export function changeGoodsSkuTraditional (goodsId, goodsSkuId, traditional) {
  const data = { traditional }
  return request({
    url: '/goods/goods/' + goodsId + '/sku/' + goodsSkuId + '/traditional',
    method: 'put',
    data: data
  })
}

// 商品排序值
export function changeGoodsSkuSortOrder (skuId, sortOrder) {
  return request({
    url: '/goods/goods/sku/' + skuId + '/sortOrder',
    method: 'put',
    data: {
      sortOrder: sortOrder
    }
  })
}



// 新增商品sku
export function addGoodsSku (goodsId, data) {
  return request({
    url: '/goods/goods/' + goodsId + '/sku',
    method: 'post',
    data: data
  })
}

// 修改商品sku
export function updateGoodsSku (goodsId, goodsSkuId, data) {
  return request({
    url: '/goods/goods/' + goodsId + '/sku/' + goodsSkuId,
    method: 'put',
    data: data
  })
}

//获取商品sku详情
export function goodsSkuDetail (goodsId, goodsSkuId) {
  return request({
    url: '/goods/goods/' + goodsId + '/sku/' + goodsSkuId,
    method: 'get'
  })
}

// 商品图片上传
export function uploadGoodsImage (data) {
  return request({
    url: '/oss/common/upload',
    method: 'post',
    data: data
  })
}

//获取商品相册列表
export function getGoodsImgList (goodsId) {
  return request({
    url: '/goods/goods/' + goodsId + '/gallery',
    method: 'get',
  })
}

// 新增商品相册
export function addGoodsImg (goodsId, data) {
  return request({
    url: `/goods/goods/${goodsId}/gallery`,
    method: 'post',
    data: data,
  })
}
// 删除商品相册
export function delGoodsImg (goodsId, id) {
  return request({
    url: `/goods/goods/${goodsId}/gallery/${id}`,
    method: 'delete',
  })
}

// 修改商品SKU限购规则
export function updateLimit (skuId, data) {
  return request({
    url: `/goods/goods/sku/${skuId}/limit`,
    method: 'put',
    data: data
  })
}

// 修改商品虚拟库存
export function updateManualQuantity (skuId, manualQuantity) {
  return request({
    url: `/goods/goods/sku/${skuId}/manualQuantity`,
    method: 'put',
    data: {
      manualQuantity: manualQuantity
    }
  })
}

// 调整商品中包装
export function updateManualPack (skuId, manualPack) {
  return request({
    url: `/goods/goods/sku/${skuId}/manualPack`,
    method: 'put',
    data: {
      manualPack: manualPack
    }
  })
}

// 删除缓存中的商品库存
export function removeCatchQuantity (query){
  return request({
    url: '/goods/goods/receive/sku/inventory',
    method: 'delete',
    params: query
  })
}

// 修改到手约展示状态
export function updateEvaluate(goodsId, skuId, evaluate){
  return request({
    url: `/goods/goods/${goodsId}/sku/${skuId}/evaluate`,
    method: 'put',
    data: {
      evaluate: evaluate
    }
  })
}

// 修改商品搜索关键词/别名
export function updateAlias(skuId, alias){
  return request({
    url: `/goods/goods/${skuId}/alias`,
    method: 'put',
    data: {
      alias: alias
    }
  })
}
